package com.example.pluginmanager.sftp;

import com.jcraft.jsch.ChannelSftp;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class PoolConfig {

    @Bean
    public GenericObjectPoolConfig<ChannelSftp> sftpPoolConfig(PoolConfigProperties poolConfigProperties){
        GenericObjectPoolConfig<ChannelSftp> objectGenericObjectPoolConfig = new GenericObjectPoolConfig<>();
        objectGenericObjectPoolConfig.setMaxIdle(poolConfigProperties.getMaxIdle());
        objectGenericObjectPoolConfig.setMinIdle(poolConfigProperties.getMinIdle());
        objectGenericObjectPoolConfig.setMaxTotal(poolConfigProperties.getMaxTotal());
        return objectGenericObjectPoolConfig;
    }

    @Bean
    public SftpGenericObjectPool sftpGenericObjectPool(SftpFactory sftpFactory,GenericObjectPoolConfig<ChannelSftp> genericObjectPoolConfig){
        return new SftpGenericObjectPool(sftpFactory, genericObjectPoolConfig);
    }

}
